package com.example.springbootsfzy.service.sunnan;

import com.example.springbootsfzy.domain.PsychologicalKnowledge;
import com.example.springbootsfzy.domain.SelectedArticles;
import com.example.springbootsfzy.mapper.PsychologicalKnowledgeMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PsychologicalKnowledgeService {
    @Autowired
    private PsychologicalKnowledgeMapper psychologicalKnowledgeMapper;

    /**
     * 分页查询所有心理知识
     * @param pageNum 当前页码
     * @param pageSize 每页显示的数量
     * @return PageInfo
     */
    public PageInfo<PsychologicalKnowledge> getPsychologicalKnowledge(int pageNum, int pageSize) {
        // 使用 PageHelper.startPage 设置分页
        PageHelper.startPage(pageNum, pageSize);
        Page<PsychologicalKnowledge> psychologicalKnowledges = psychologicalKnowledgeMapper.getAllPsychologicalKnowledge();
        return new PageInfo<>(psychologicalKnowledges);
    }

    /**
     * 根据consultantId查询心理知识
     * @param consultantId 咨询师id
     * @return List
     */
    public List<PsychologicalKnowledge> selectByConsultantId(int consultantId) {
        return psychologicalKnowledgeMapper.selectByConsultantId(consultantId);
    }

    /**
     * 添加心理知识
     * @param psychologicalKnowledge 心理知识对象
     * @return int 响应结果
     */
    public int insert(PsychologicalKnowledge psychologicalKnowledge) {
        return psychologicalKnowledgeMapper.insert(psychologicalKnowledge);
    }

    /**
     * 根据id删除心理知识
     * @param psychologicalKnowledgeId 心理知识id
     * @return int 响应结果
     */
    public int deleteByPrimaryKey(int psychologicalKnowledgeId) {
        return psychologicalKnowledgeMapper.deleteByPrimaryKey(psychologicalKnowledgeId);
    }

    /**
     * 根据id更新心理知识
     * @param psychologicalKnowledge 心理知识对象
     * @return int 响应结果
     */
    public int updateByPrimaryKeySelective(PsychologicalKnowledge psychologicalKnowledge) {
        return psychologicalKnowledgeMapper.updateByPrimaryKeySelective(psychologicalKnowledge);
    }


}
